package cn.kgc.vote.service;

import cn.kgc.vote.dao.VoteDao;
import cn.kgc.vote.pojo.Options;
import cn.kgc.vote.pojo.Subjects;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Component
@Transactional
public class VoteServiceImpl implements VoteService {

    @Resource
    private VoteDao voteDao;

    @Override
    @Transactional(readOnly = true)
    public List<Subjects> showAllSubjects() {
        return voteDao.queryAllSubjects();
    }

    @Override
    public Subjects showSubjectById(Integer id) {
        return voteDao.querySubjectById(id);
    }

    @Override
    public Boolean updateViewTimes(Integer id) {
        return voteDao.updateViewTimes(id) == 1;
    }

    @Override
    public Boolean updateTotalVotes(Integer id) {
        return voteDao.updateTotalVotes(id) == 1;
    }

    @Override
    public List<Options> showOptionsBySid(Integer sid) {
        return voteDao.queryOptionsBySid(sid);
    }

    @Override
    public Boolean updateVote(Integer id) {
        return voteDao.updateVote(id) == 1;
    }

}
